< previous page page_655 next page >

Page 655
In this example, you can drag the icons on the right side of the form onto the list box to have the words located next to those icons loaded into the list box. This is a fairly sophisticated example, but youll learn to build this by the time you finish reading the chapter. Of course, you must learn to walk before you can run, so lets first start with a fairly simple example.
Automatic Drag and Drop
Visual Basic allows you to set the DragMode property of most controls to 1 - Automatic. This allows you to click and hold the mouse over the control and then move the mouse. A gray outline will appear signifying that youre in drag mode. When you release the mouse, the outline goes away, but the control stays at the same location where it was before. Lets try this out.
EXERCISE
Using Automatic Drag and Drop
1. Start a new project in Visual Basic.
2. Add a label control to the default form.
3. Set the Name property to lblDrag.
4. Set the BorderStyle property to 1 - Fixed Single just so you can see the label a little better.
5. Set the Caption property to Drag Me.
6. Set the DragMode property to 1 - Automatic.
7. Run the project.
8. Click and hold down the left mouse button over the label.
9. Drag your mouse around the form to see the outline of the label appear.
analysis.gifAs you can see by the above exercise, it is very easy to get drag and drop to work.

Well, that was a drag! Okay, okay, bad pun. Lets now have it actually do something. Lets add the ability to drop the control somewhere.

 
< previous page page_655 next page >

If you like this book, buy it!